/**
 * 
 */
package com.jie.eclipse.pan.action;

import org.eclipse.jface.action.Action;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.internal.WorkbenchPage;
import org.eclipse.ui.part.EditorActionBarContributor;

import com.jie.eclipse.pan.editors.PLLFormEditor;
import com.jie.eclipse.pan.editors.PLLJspFormEditor;
import com.jie.eclipse.pan.utils.Utils;

/**
 * @author yanjie
 *
 */
public class BaseAction extends Action{
	private EditorActionBarContributor ebc = null;

	public BaseAction(EditorActionBarContributor ebc,String id) {
		this.ebc = ebc;
		if(id != null)
			this.setId(id);
		else
			this.setId(BaseAction.class.getName());  
        this.setText("Base Action");  
    } 
	
	@Override
	public void run() {
		WorkbenchPage page = (WorkbenchPage)this.ebc.getPage();
		if(page.getActivePart() instanceof PLLFormEditor){
			PLLFormEditor pll = (PLLFormEditor)page.getActivePart();
			if("alt1".equals(this.getId()) && pll.getActiveEditor() != pll.getPllPage()){
				pll.setActivePage("com.jie.eclipse.pan.editors.page.pllpage");
			}else if("alt2".equals(this.getId()) && pll.getActiveEditor() != pll.getPllEditor()){
				pll.setActiveEditor(pll.getPllEditor());
			}else if("alt3".equals(this.getId()) && pll.getActiveEditor() != pll.getUiEditor()){
				pll.setActiveEditor(pll.getUiEditor());
			}else if("alt4".equals(this.getId()) && pll.getActiveEditor() != pll.getBackEditor()){
				pll.setActiveEditor(pll.getBackEditor());
			}else if("alt5".equals(this.getId()) && pll.getActiveEditor() != pll.getOldEditor()){
				pll.setActiveEditor(pll.getOldEditor());
			}else if("alt`".equals(this.getId())){
				pll.doNextPage();
			}else if("altshift`".equals(this.getId())){
				pll.doPrePage();
			}else if("alt_O".equals(this.getId())){
				pll.openOldPage();
			}
		}else if(page.getActivePart() instanceof PLLJspFormEditor){
			PLLJspFormEditor pll = (PLLJspFormEditor)page.getActivePart();
			if("alt1".equals(this.getId()) && pll.getUiEditor() != null && pll.getActiveEditor() != pll.getUiEditor()){
				pll.setActiveEditor(pll.getUiEditor());
			}else if("alt2".equals(this.getId()) && pll.getBackEditor() !=null && pll.getActiveEditor() != pll.getBackEditor()){
				pll.setActiveEditor(pll.getBackEditor());
			}else if("alt3".equals(this.getId()) && pll.getOldEditor() !=null && pll.getActiveEditor() != pll.getOldEditor()){
				pll.setActiveEditor(pll.getOldEditor());
			}else if("alt`".equals(this.getId())){
				pll.doNextPage();
			}else if("altshift`".equals(this.getId())){
				pll.doPrePage();
			}else if("alt_O".equals(this.getId())){
				pll.openOldPage();
			}
		}
	}
}
